#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

#include "Movie.h"

Movie::Movie(string title, int dd, int mm, int yyyy, vector<string> actors, vector<string> genres, string trailer):
release_date(dd, mm, yyyy)
{
	this->title = title;
	this->trailer = trailer;
	this->actors = actors;
	this->genres = genres;
}
Movie::~Movie()
{
}

string Movie::get_title()const
{
	return title;
}
Date Movie::get_date()const
{
	return release_date;
}
string Movie::get_trailer()const
{
	return trailer;
}
vector<string> Movie::get_actors() const
{
	return actors;
}
vector<string> Movie::get_genres() const
{
	return genres;
}
bool Movie::contains_genre(string g)
{
	string aux;
	transform(g.begin(), g.end(), g.begin(), tolower);

	for (unsigned int i=0; i<genres.size(); i++)
	{
		aux = genres[i];
		transform(genres[i].begin(), genres[i].end(), aux.begin(), tolower);
		if(aux.find(g) < aux.length())
		{
			return true;
		}
	}
	return false;
}
bool Movie::contains_actor(string a)
{
	transform(a.begin(), a.end(), a.begin(), tolower);
	string aux;

	for (unsigned int i=0; i<actors.size(); i++)
	{
		aux = actors[i];
		transform(actors[i].begin(), actors[i].end(), aux.begin(), tolower);
		if(aux.find(a) < aux.length())
		{
			return true;
		}
	}
	return false;
}
string Movie::to_string()
{
	ostringstream oss;

	oss << endl << "Title: " << title << endl;
	oss << "Release date: " << release_date.to_string() << endl;
	oss << "Actors:";
	for (unsigned int i=0; i<actors.size(); i++)
	{
		if (i == 0)
		{
			oss << " " + actors[i];
			continue;
		}
		oss << ", " + actors[i];
	}
	oss << endl << "Genres:";
	for (unsigned int i=0; i<genres.size(); i++)
	{
		if (i == 0)
		{
			oss << " " + genres[i];
			continue;
		}
		oss << ", " + genres[i];
	}
	oss << endl << "Trailer:\n";

	return oss.str();
}